package edu.pku.sei.modeler.neditor.model;

import java.util.ArrayList;
import java.util.List;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.notation.core.Notation;
import edu.pku.sei.modeler.model.notation.core.NotationFactory;
import edu.pku.sei.modeler.model.notation.core.ShapeConstance;
import edu.pku.sei.modeler.model.notation.core.ShapeNode;
import edu.pku.sei.modeler.model.notation.shape.ConnectionTemplate;

public class Diagram extends MetaModelElement{
	private Notation notation;
	
	private NotationFactory factory_instance;
	//private NotationEditor editor_instance;
	/**
	 * @deprecated
	 */
	public NotationFactory getFactoryInstance(){
		
		return factory_instance;
	}
	
	public Diagram(){
		//factory_instance = NotationFactory.createFactory(NotationPackage.createPackage());
		//this.setModel(this);
	}
	
	private List<MetaModelElement> shapes = new ArrayList();
	
	private List<MetaModelElement> links = new ArrayList();
	
	public List getMainEditorLinks(){
		return links;
	}
	
	public List getMainEditorNodes(){
		return shapes;
	}
	public void addLinks(MetaModelElement node){
		links.add(node);
		notation.getNotations().add((ShapeNode)node);
		this.fireStructureChange(ShapeConstance.REFRESH_ALL, node);
	}
	public void removeLinkes(MetaModelElement node){
		links.remove(node);
		notation.getNotations().remove((ShapeNode)node);
		this.fireStructureChange(ShapeConstance.REFRESH_ALL, node);
	}
	@SuppressWarnings("unchecked")
	public void addNode(MetaModelElement node){
		shapes.add(node);
		notation.getNotations().add((ShapeNode)node);
		this.fireStructureChange(ShapeConstance.REFRESH_ALL, node);
	}
	public void removeNode(Object node){
		shapes.remove(node);
		notation.getNotations().remove((ShapeNode)node);
		this.fireStructureChange(ShapeConstance.REFRESH_ALL, node);
	}
	public List getNodes() {
		return shapes;
	}
	
	
	/*public void setEditor(NotationEditor editor_instance) {
		this.editor_instance = editor_instance;
	}*/

/*	public NotationEditor getEditor() {
		return editor_instance;
	}*/

	public void setFactory(NotationFactory factory_instance) {
		this.factory_instance = factory_instance;
	}

	public Notation getNotation() {
		return notation;
	}

	public void setNotation(Notation notation) {
		this.notation = notation;
		shapes.clear();
		links.clear();
		
		for(ShapeNode n:notation.getNotations()) {
			if(n instanceof ConnectionTemplate) {
				links.add(n);
			} else {
				shapes.add(n);
			}
		}
	}


}
